home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0185_Size form to fit WIN95 client area.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-11-29  |  2.3 KB  |  41 lines

  1. // ================================================================================================
  2. // Sizes the specified form perfectly in the Win95/NT4 client area, outside the taskbar, regardless
  3. // of the taskbar's size or location.  Freeware by Peter M. Jagielski.  Works best if called from
  4. // your main form's FormCreate - just pass this proc the name of your main form.  Be sure to
  5. // include the Windows unit in your USES clause.
  6. // ================================================================================================
  7. procedure SizeForWin95(MyForm: TForm);
  8. var
  9.   TaskBarHandle: HWnd;    // Handle to the Win95 Taskbar
  10.   TaskBarCoord:  TRect;   // Coordinates of the Win95 Taskbar
  11.   CxScreen,               // Width of screen in pixels
  12.   CyScreen,               // Height of screen in pixels
  13.   CxFullScreen,           // Width of client area in pixels
  14.   CyFullScreen,           // Heigth of client area in pixels
  15.   CyCaption:     Integer; // Height of a window's title bar in pixels
  16. begin
  17.   TaskBarHandle := FindWindow('Shell_TrayWnd',Nil); // Get Win95 Taskbar handle
  18.   if TaskBarHandle = 0 then // We're running Win 3.x or WinNT w/o Win95 shell, so just maximize
  19.     MyForm.WindowState := wsMaximized
  20.   else // We're running Win95 or WinNT w/Win95 shell
  21.     begin
  22.       MyForm.WindowState := wsNormal;
  23.       GetWindowRect(TaskBarHandle,TaskBarCoord);        // Get coordinates of Win95 Taskbar
  24.       CxScreen        := GetSystemMetrics(SM_CXSCREEN); // Get various screen dimensions and set form's width/height
  25.       CyScreen        := GetSystemMetrics(SM_CYSCREEN);
  26.       CxFullScreen    := GetSystemMetrics(SM_CXFULLSCREEN);
  27.       CyFullScreen    := GetSystemMetrics(SM_CYFULLSCREEN);
  28.       CyCaption       := GetSystemMetrics(SM_CYCAPTION);
  29.       MyForm.Width    := CxScreen - (CxScreen - CxFullScreen) + 1;
  30.       MyForm.Height   := CyScreen - (CyScreen - CyFullScreen) + CyCaption + 1;
  31.       MyForm.Top      := 0;
  32.       MyForm.Left     := 0;
  33.       MyForm.Position := poDefault;
  34.       if (TaskBarCoord.Top = -2) and (TaskBarCoord.Left = -2) then // Taskbar on either top or left
  35.         if TaskBarCoord.Right > TaskBarCoord.Bottom then // Taskbar on top
  36.           MyForm.Top  := TaskBarCoord.Bottom
  37.         else // Taskbar on left
  38.           MyForm.Left := TaskBarCoord.Right;
  39.     end;
  40. end;
  41.